﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ras2ClassLib;

namespace Ras2Form
{
    public partial class SongDlg : Form
    {
        private UISong m_song;
        private bool m_bNewSong = false;
        private int m_selectedPerformer = 0;

        public bool NewSong
        {
            get { return m_bNewSong; }
            set { m_bNewSong = value; }
        }

        public UISong Song
        {
            get
            {
                m_song.Name = m_txtName.Text;
                m_song.PerformerID = m_selectedPerformer;
                m_song.MP3Path = m_txtMP3Path.Text;
                m_song.Description = m_txtDescription.Text;
                return m_song;
            }
            set
            {
                m_song = value;
                m_txtName.Text        = m_song.Name;
                m_txtMP3Path.Text     = m_song.MP3Path;
                m_txtDescription.Text = m_song.Description;
                if (NewSong)
                    m_btnOK.Text = "Nýskrá";
                else
                    m_btnOK.Text = "Í lagi";
            }
        }

        public SongDlg()
        {
            InitializeComponent();
        }

        private void OnLoad(object sender, EventArgs e)
        {
            CenterToParent();

            if (!this.DesignMode)
            {
                PerformerController controller = new PerformerController();
                int idx = 0;
                foreach (Performer s in controller.GetAllPerformers())
                {
                    m_cPerformers.Items.Add(new TableItem(s.ID, s.Name));
                    if (m_song.PerformerID == s.ID)
                        m_selectedPerformer = idx;
                    idx++;
                }

                m_cPerformers.SelectedIndex = m_selectedPerformer;
            }
        }

        private void OnSelItem(object sender, EventArgs e)
        {
            m_selectedPerformer = m_cPerformers.SelectedIndex;
        }
    }
}
